package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dto.DataManager;

/**
 * Servlet implementation class AddCard
 */
@WebServlet("/AddCard")
public class AddCard extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddCard() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DataManager dataManager = new DataManager();
		
		int i5c = Integer.parseInt(request.getParameter("5c"));
		if(i5c > 0)
			for(int i = 0; i < i5c; i++)
				dataManager.addCard(50000);
		int i1t = Integer.parseInt(request.getParameter("1t"));
		if(i1t > 0)
			for(int i = 0; i < i1t; i++)
				dataManager.addCard(100000);
		int i2t = Integer.parseInt(request.getParameter("2t"));
		if(i2t > 0)
			for(int i = 0; i < i2t; i++)
				dataManager.addCard(200000);
		int i5t = Integer.parseInt(request.getParameter("5t"));
		if(i5t > 0)
			for(int i = 0; i < i5t; i++)
				dataManager.addCard(500000);
		int i1tr = Integer.parseInt(request.getParameter("1tr"));
		if(i1tr > 0)
			for(int i = 0; i < i1tr; i++)
				dataManager.addCard(1000000);
		int i5tr = Integer.parseInt(request.getParameter("5tr"));
		if(i5tr > 0)
			for(int i = 0; i < i5tr; i++)
				dataManager.addCard(5000000);
		int i10tr = Integer.parseInt(request.getParameter("10tr"));
		if(i10tr > 0)
			for(int i = 0; i < i10tr; i++)
				dataManager.addCard(10000000);
		response.sendRedirect("viewCardAdmin.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
